{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test Case: Server embed"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Expected result:\n",
    "\n",
    "* The initial output should be \"BokehJS is loading...\"\n",
    "* The output should be updated to /[Logo] BokehJS x.y.z successfully loaded"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "from bokeh.layouts import row, widgetbox\n",
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.models.widgets import Slider, TextInput\n",
    "from bokeh.plotting import figure, output_notebook, show\n",
    "\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def modify_doc(doc):\n",
    "    # Set up data\n",
    "    N = 200\n",
    "    x = np.linspace(0, 4*np.pi, N)\n",
    "    y = np.sin(x)\n",
    "    source = ColumnDataSource(data=dict(x=x, y=y))\n",
    "\n",
    "    # Set up plot\n",
    "    plot = figure(plot_height=400, plot_width=400, title=\"my sine wave\",\n",
    "                  tools=\"crosshair,pan,reset,save,wheel_zoom\",\n",
    "                  x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])\n",
    "\n",
    "    plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)\n",
    "\n",
    "    # Set up widgets\n",
    "    text = TextInput(title=\"title\", value='my sine wave')\n",
    "    offset = Slider(title=\"offset\", value=0.0, start=-5.0, end=5.0, step=0.1)\n",
    "    amplitude = Slider(title=\"amplitude\", value=1.0, start=-5.0, end=5.0, step=0.1)\n",
    "    phase = Slider(title=\"phase\", value=0.0, start=0.0, end=2*np.pi)\n",
    "    freq = Slider(title=\"frequency\", value=1.0, start=0.1, end=5.1, step=0.1)\n",
    "\n",
    "    # Set up callbacks\n",
    "    def update_title(attrname, old, new):\n",
    "        plot.title.text = text.value\n",
    "\n",
    "    text.on_change('value', update_title)\n",
    "\n",
    "    def update_data(attrname, old, new):\n",
    "\n",
    "        # Get the current slider values\n",
    "        a = amplitude.value\n",
    "        b = offset.value\n",
    "        w = phase.value\n",
    "        k = freq.value\n",
    "\n",
    "        # Generate the new curve\n",
    "        x = np.linspace(0, 4*np.pi, N)\n",
    "        y = a*np.sin(k*x + w) + b\n",
    "\n",
    "        source.data = dict(x=x, y=y)\n",
    "\n",
    "    for w in [offset, amplitude, phase, freq]:\n",
    "        w.on_change('value', update_data)\n",
    "\n",
    "\n",
    "    # Set up layouts and add to document\n",
    "    inputs = widgetbox(text, offset, amplitude, phase, freq)\n",
    "\n",
    "    doc.add_root(row(inputs, plot, width=800))\n",
    "    doc.title = \"Sliders\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Expected Result:\n",
    "    \n",
    "* A Bokeh line plot should be rendered\n",
    "* Dragging the sliders should update the line glyph\n",
    "* Changing the title text area and hitting Enter should update the plot title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "show(modify_doc)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
